/**
 * COPYRIGHT HangZhou Trustway Technology Company Limited
 * All right reserved.
 */
package com.robam.cloud.authcenter.helper.impl;

import com.robam.cloud.authcenter.helper.WechatAccessTokenGateway;
import com.robam.cloud.authcenter.helper.WechatJspApiTicketGateway;
import com.robam.cloud.authcenter.manager.WechatAccessTokenManager;
import com.robam.cloud.cache.annotation.CacheExpire;
import com.robam.cloud.common.bean.authcenter.entity.AuthPlatform;
import com.robam.cloud.common.util.wechat.WechatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author 薛铁琪
 * @CreateTime 2020-07-26 21:47
 * @Version 1.0
 */
@Component
public class WechatJspApiTicketOriginGateway extends WechatJspApiTicketGateway {
    @Autowired
    WechatAccessTokenManager wechatAccessTokenManager;
    @Autowired
    WechatUtil wechatUtil;

    @Override
    @CacheExpire(expire = 3600)
    @Cacheable(value = "AUTH-CENTER", key = "'JsapiTicket'+'appid_' + #authPlatform.getAppId()", unless = "#result == null")
    public String requestTicket(AuthPlatform authPlatform) {
        WechatAccessTokenGateway wechatAccessTokenGateway = wechatAccessTokenManager.callAccessTokenMeth(authPlatform.getAccesstokentype());
        String token = wechatAccessTokenGateway.requestToken(authPlatform);
        return wechatUtil.getTicket(token);
    }
}
